package model;
import java.util.Date;


public class Point {
	public double lon, lat, elevation;
	public Date time;

	public Point(double lat2, double lon2, double elevation2, Date d) {
		lat = lat2;
		lon = lon2;
		elevation = elevation2;
		time = d;
	}
	public Point() {
	}
	
	public String toString() {
		return "("+lat+", "+lon+"):"+elevation+"; "+time;
	}
	
	public double distanceTo(Point p) {
		
		double dist = distFrom(lat, lon, p.lat, p.lon);
		
		return dist;
	}
	
	public double paceTo(Point p) {
		return Math.abs(time.getTime() - p.time.getTime())/distanceTo(p)/60;
	}
	
	public static double distFrom(double lat1, double lng1, double lat2, double lng2) {
	    double earthRadius = 3958.75;
	    double dLat = Math.toRadians(lat2-lat1);
	    double dLng = Math.toRadians(lng2-lng1);
	    double a = Math.sin(dLat/2) * Math.sin(dLat/2) +
	               Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) *
	               Math.sin(dLng/2) * Math.sin(dLng/2);
	    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
	    double dist = earthRadius * c;

	    int meterConversion = 1609;

	    return dist * meterConversion;
    }
}